package lbhlll;

import java.util.concurrent.FutureTask;

public class deadlock {
    static Object o1 = new Object();
    static Object o2 = new Object();

    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (o1) {
                    System.out.println("获取到了o1对象，试图获取o2对象");
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (o2) {
                        System.out.println("获取到了o2对象");
                    }
                }

            }
        },"线程1").start();


        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (o2) {
                    System.out.println("获取到了o2对象，试图获取o1对象");
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (o1) {
                        System.out.println("获取到了o1对象");
                    }
                }
            }
        },"线程2").start();
    }
}
